package com.adou.common.util;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class sendTelMsg {
    private static final Logger logger = LoggerFactory.getLogger(sendTelMsg.class);

    public static String startdayu(String tel, String sign, String template, String extend, String body) {
        String result = "";
        try {
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod(IConfig.get("DYUrl"));
            post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
            post.addRequestHeader("X-Ca-Key", IConfig.get("DYKey"));
            post.addRequestHeader("X-Ca-Secret", IConfig.get("DYSecret"));
            NameValuePair[] data = {
                    new NameValuePair("rec_num", tel),
                    new NameValuePair("sms_template_code", template),
                    new NameValuePair("sms_free_sign_name", sign),
                    new NameValuePair("sms_type", "normal"),
                    new NameValuePair("extend", extend),
                    new NameValuePair("sms_param", body)
            };
            post.setRequestBody(data);
            client.executeMethod(post);
            result = new String(post.getResponseBodyAsString().getBytes("utf-8"));
            post.releaseConnection();

        } catch (Exception e) {
            logger.error("手机短信发送错误:" + e.toString());
        }
        return result;
    }
}
